package com.example.kuaizu.mapper;

import com.example.kuaizu.em.ProjectDelectStatus;
import com.example.kuaizu.pojo.ProjectJoin;
import com.example.kuaizu.pojo.ProjectReview;
import com.example.kuaizu.pojo.dto.ApplicationProjectListDTO;
import com.example.kuaizu.pojo.dto.UserEmailDao;
import com.example.kuaizu.pojo.ov.ProjectOv;
import com.example.kuaizu.pojo.ov.UserProfileOv;
import com.example.kuaizu.pojo.pram.ProjcetIds;
import kuaizu.common.tablepojo.Project;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProjectMapper {

    //创建项目
    public Integer createProject(Project pro);

    //加入项目
    int joinProject(ProjectReview projectJoin);

    //查询单个项目信息
    @Select("select * from project where id=#{projectId}")
    Project SelectProjectInfo(Integer projectId);

    //查询自己的所有项目
    @Select("select p.* ,s.schoolname from project p left join school s on p.school=s.id where p.creator_openid=#{openid}")
    List<ProjectOv> SelectProjectList(String openid);

    //查询指定的项目
    ProjectJoin selectProjectJoin(@Param("projectId") Integer projectid, @Param("openid") String openid);

    //查询指定项目的申请人人信息
    List<ProjectJoin> selectProject(@Param("projectId") Integer projectid, @Param("openid") String openid, @Param("status") Integer status);

    //审核信息更细
    int UpdateProjectJoin(@Param("projectId") Integer projectid, @Param("id") String id, @Param("status") Integer status);

    //查询所有的项目集合分页 TODO 添加审核通过的条件
    List<ProjectOv> selectAllProjectList(Integer school);

    //查询项目的申请人的信息
    //@Select("select user_profile.* from user_profile join project_review on user_profile.openid = project_review.openid where project_review.project_id = #{id}")
    List<UserProfileOv> selectProjectUserJoin(@Param("id") Integer id, @Param("status") Integer status);

    /**
     * 获取当前登录用户申请的所有项目列表以及项目信息
     *
     * @param openid 当前登录用户的openid
     * @return 项目列表
     */
    List<ApplicationProjectListDTO> queryApplicationProject(@Param("openid") String openid);

    //增加阅读量
    @Update("update project set lookcount = lookcount + 1 where id = #{id}")
    void updateLookProject(Integer id);

    //向表中添加删除数据
    void copyProjectToDelectTable(Project pro);

    //删除项目指定
    @Delete("delete from project where id = #{id}")
    void deleteProject(Integer id);

    //  查询项目的Id
    Project selectProjectId(Project pro);


    //根据项目id查询项目信息
    @Select("select p.*,s.schoolname from project p left join school s on p.school = s .id where p.id=#{id}")
    ProjectOv selectProjectById(String id);

    //增加投递量
    @Update("update project set application_count = application_count + 1 where id = #{id}")
    void updateApplicationCount(Integer id);

    //删除指定的id和openid对应的项目
    @Delete("delete from project_review where project_id = #{id} and openid = #{openid}")
    void delectJoinProject(@Param("id") Integer id, @Param("openid") String openid);

    //判断是否加入指定项目
    @Select("select id,openid,project_id AS projectid,is_approved AS status from project_review where project_id = #{id} and openid = #{openid}")
    ProjectJoin isJoin(@Param("openid") String openid, @Param("id") Integer id);

    List<UserEmailDao> selectUserEmailDao(@Param("id") Integer id, @Param("status") Integer status);

    @Delete("delete from project_review where openid = #{openId}")
    void delectProjectReviewInfo(String openId);

    //删除项目神表中的信息
    @Delete("Delete from project_review where project_id = #{id}")
    void delectProjectReview(Integer id);

    //删除邮件推广表中的信息
    @Delete("delete from email_promotion where project_id = #{id}")
    void delectEmailPromotion(Integer id);
    //设置对应的邮件推广状态
    @Update("UPDATE project SET email_promotion_status = #{projectDelectStatus} WHERE id = #{projectId}")
    void updateEmailPromotionStatus(String projectId, ProjectDelectStatus projectDelectStatus);
    @Select("select * from project_review where project_id = #{id} and openid = #{openid}")
    ProjectReview selectByIdAndOpenId(@Param("id") Integer id,@Param("openid") String openid);

    List<ProjectOv> selectProjectByIds(ProjcetIds projectIds);

    @Update("UPDATE project_review SET is_approved = '1' WHERE project_id = #{projectId} and openid = #{openId}")
    void projectReview(@Param("projectId") Integer projectId, @Param("openId") String openId);

    //查询制定项目投递的人才信息
    List<UserProfileOv> projectDeliveryOliveBranch(@Param("id") Integer id,@Param("openid") String openId);
}
